<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Tools_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
		$this->load->helper('directory');
		$this->tools_folder =  BASEPATH."../application/modules/";
    }

	public function load_tools()
	{
		$data = array ();
		$map = directory_map($this->tools_folder, 1);
		foreach ($map as $file)
		{
			include_once ($this->tools_folder.$file);
			$names = explode ('.', $file);
			$class_name = ucfirst($names[1]);
			$module = new $class_name;
			$module_name = $module->module_name;
			$data [$class_name]['name'] = $module_name;
			$data [$class_name]['subfunctions'] = $module->module_subfunctions;
		}
		return $data;
	}


	public function exec_tools($class_name, $func_name)
	{
		$file = $this->tools_folder.'module.'.strtolower($class_name).'.php';
		if (!is_file($file))
		{
			return 'Не могу прочитать файл модуля';
		}
		include_once ($file);
		$module = new $class_name;
		return $module->$func_name();
	}


}

